using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUSLayer;

namespace QuanLyThuVien
{
    public partial class frmXoaSach : Form
    {
        public frmXoaSach()
        {
            InitializeComponent();
        }

        

        private void btnXoa_Click(object sender, EventArgs e)
        {
            try
            {
                int ma = int.Parse(txtMasach.Text);
                SachDto sach = SachBus.TimKiem(ma);
                
                if (sach.TINHTRANG == false)
                {
                    if (MessageBox.Show("Ban co that su muon xoa", "Thong bao", MessageBoxButtons.YesNo) == DialogResult.OK)
                        SachBus.Xoa(ma);
                }
                else 
                    MessageBox.Show("Sach nay dang duoc muon");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            try
            {
                int ma = int.Parse(txtMasach.Text);
                SachDto sach = SachBus.TimKiem(ma);
                //Neu sach khong co trong csdl
                if (sach == null)
                    MessageBox.Show("Khong co thong tin sach");
                else
                {
                    labelTensach.Text = sach.TENSACH;
                    labelTacgia.Text = sach.MATACGIA.ToString();
                    labelTheloai.Text = sach.MALOAISACH.ToString();
                    labelNamXB.Text = sach.NAMXUATBAN.ToString();
                    labelGia.Text = sach.GIA.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }     
    }
}